package com.stars.module.department.controller;

import com.stars.base.entity.CommonDTO;
import com.stars.base.entity.Result;
import com.stars.module.department.entity.StarDept;
import com.stars.module.department.service.StarDeptService;
import org.springframework.web.bind.annotation.*;

/**
 * @author : mango
 * @version : 1.0
 * @date : 2022/10/31 11:21
 * @description : 部门控制器
 */
@RestController
@RequestMapping("/starDept")
public class StarDeptController {

    private final StarDeptService deptService;

    public StarDeptController(StarDeptService deptService) {
        this.deptService = deptService;
    }

    @RequestMapping("/loadAllDept")
    public Result loadAllDept(){
        return Result.success(deptService.loadAllDept());
    }

    /**
     * 根据机构ID获取所属部门
     * @return
     */
    @RequestMapping("/loadAllDeptByUnitId")
    public Result loadAllDeptByUnitId(String unitId,String fid){
        return Result.success(deptService.loadAllDeptByUnitId(unitId,fid));
    }

    @RequestMapping("/loadDeptByFid")
    public Result loadDeptByFid(@RequestBody CommonDTO dto){
        return Result.success(deptService.loadDeptByFid(dto));
    }

    @GetMapping("/loadDeptById")
    public Result loadDeptById(String id){
        return Result.success(deptService.loadDeptById(id));
    }

    @PostMapping("/saveDept")
    public Result saveDept(@RequestBody StarDept dept){
        return Result.result(deptService.saveOrUpdateDept(dept));
    }

    @PostMapping("removeDept")
    public Result removeDept(String id){
        return Result.result(deptService.removeDept(id));
    }

    @RequestMapping("/getMaxIndex")
    public Result getMaxIndex (String fid,String unitId) {
        return Result.success(deptService.getMaxIndex(fid,unitId));
    }
}
